home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH6 / EMAGA6 / control / client / misc / presetkeys.cs < prev    next >
Text File  |  2006-07-02  |  5KB  |  165 lines

  1. //============================================================================
  2. // control/client/misc/presetkeys.cs
  3. //
  4. // Copyright (c) 2003 Kenneth C. Finney
  5. //============================================================================
  6.  
  7. if ( IsObject(PlayerKeymap) )  // If we already have a player key map,
  8.    PlayerKeymap.delete();        // delete it so that we can make a new one
  9. new ActionMap(PlayerKeymap);
  10.  
  11. $movementSpeed = 1;             // m/s   for use by movement functions
  12.  
  13.  
  14. //------------------------------------------------------------------------------
  15. // Non-remapable binds
  16. //------------------------------------------------------------------------------
  17.  
  18. function DoExitGame()
  19. {
  20.    MessageBoxYesNo( "Quit Mission", "Exit from this Mission?", "Quit();", "");
  21. }
  22.  
  23.  
  24. //============================================================================
  25. // Motion Functions
  26. //============================================================================
  27.  
  28. function GoLeft(%val)
  29. //----------------------------------------------------------------------------
  30. // "strafing"
  31. //----------------------------------------------------------------------------
  32. {
  33.    $mvLeftAction = %val;
  34. }
  35.  
  36. function GoRight(%val)
  37. //----------------------------------------------------------------------------
  38. // "strafing"
  39. //----------------------------------------------------------------------------
  40. {
  41.    $mvRightAction = %val;
  42. }
  43.  
  44. function GoAhead(%val)
  45. //----------------------------------------------------------------------------
  46. // running forward
  47. //----------------------------------------------------------------------------
  48. {
  49.    $mvForwardAction = %val;
  50. }
  51.  
  52. function BackUp(%val)
  53. //----------------------------------------------------------------------------
  54. // running backwards
  55. //----------------------------------------------------------------------------
  56. {
  57.    $mvBackwardAction = %val;
  58. }
  59.  
  60. function DoYaw(%val)
  61. //----------------------------------------------------------------------------
  62. // looking, spinning or aiming horizontally by mouse or joystick control
  63. //----------------------------------------------------------------------------
  64. {
  65.    $mvYaw += %val * ($cameraFov / 90) * 0.02;
  66. }
  67.  
  68. function DoPitch(%val)
  69. //----------------------------------------------------------------------------
  70. // looking vertically by mouse or joystick control
  71. //----------------------------------------------------------------------------
  72. {
  73.    $mvPitch += %val * ($cameraFov / 90) * 0.02;
  74. }
  75.  
  76. function DoJump(%val)
  77. //----------------------------------------------------------------------------
  78. // momentary upward movement, with character animation
  79. //----------------------------------------------------------------------------
  80. {
  81.    $mvTriggerCount2++;
  82. }
  83.  
  84. //============================================================================
  85. // View Functions
  86. //============================================================================
  87.  
  88. function Toggle3rdPPOVLook( %val )
  89. //----------------------------------------------------------------------------
  90. // enable the "free look" feature. As long as the mapped key is pressed,
  91. // the player can view his avatar by moving the mouse around.
  92. //----------------------------------------------------------------------------
  93. {
  94.    if ( %val )
  95.       $mvFreeLook = true;
  96.    else
  97.       $mvFreeLook = false;
  98. }
  99.  
  100. function MouseAction(%val)
  101. {
  102.    $mvTriggerCount0++;
  103. }
  104.  
  105. function Toggle1stPPOV(%val)
  106. //----------------------------------------------------------------------------
  107. // switch between 1st and 3rd person point-of-views.
  108. //----------------------------------------------------------------------------
  109. {
  110.    if (%val)
  111.    {
  112.       $firstPerson = !$firstPerson;
  113.       ServerConnection.setFirstPerson($firstPerson);
  114.    }
  115. }
  116.  
  117.  
  118. //============================================================================
  119. // keyboard control mappings
  120. //============================================================================
  121. // these ones available when player is in game
  122. PlayerKeymap.Bind( mouse, button0, MouseAction ); // left mouse button
  123. PlayerKeymap.Bind(keyboard, w, GoAhead);
  124. PlayerKeymap.Bind(keyboard, s, BackUp);
  125. PlayerKeymap.Bind(keyboard, a, GoLeft);
  126. PlayerKeymap.Bind(keyboard, d, GoRight);
  127. PlayerKeymap.Bind(keyboard, space, DoJump );
  128. PlayerKeymap.Bind(keyboard, z, Toggle3rdPPOVLook );
  129. PlayerKeymap.Bind(keyboard, tab, Toggle1stPPOV );
  130. PlayerKeymap.Bind(mouse, xaxis, DoYaw );
  131. PlayerKeymap.Bind(mouse, yaxis, DoPitch );
  132.  
  133. // these ones are always available
  134.  
  135. GlobalActionMap.Bind(keyboard, escape, DoExitGame);
  136. GlobalActionMap.Bind(keyboard, tilde, ToggleConsole);
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. function dropCameraAtPlayer(%val)
  144. {
  145.    if (%val)
  146.       commandToServer('dropCameraAtPlayer');
  147. }
  148.  
  149. function dropPlayerAtCamera(%val)
  150. {
  151.    if (%val)
  152.       commandToServer('DropPlayerAtCamera');
  153. }
  154. function toggleCamera(%val)
  155. {
  156.    if (%val)
  157.    {
  158.       commandToServer('ToggleCamera');
  159.       }
  160. }
  161.  
  162. PlayerKeymap.bind(keyboard, "F8", dropCameraAtPlayer);
  163. PlayerKeymap.bind(keyboard, "F7", dropPlayerAtCamera);
  164.  
  165. PlayerKeymap.bind(keyboard, "F6", toggleCamera);